package cn.ecut.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.ecut.Bean.Apply;

import cn.ecut.DBConnection.OpenConnection;

public class ApplyDao {
    public boolean apply(Apply apply){
        OpenConnection db = new OpenConnection();
        Connection conn = db.getConnection();
        String sql = "insert into apply(name,id, buildname,floorname,roomname,shopname,sex,phone) values(?,?,?,?,?,?,?,?)";
        int i = 0;
        try{
            conn.setAutoCommit(false);//设置为不自动提交
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setString(1, apply.getName());
            pst.setString(2, apply.getId());
            pst.setString(3, apply.getBuildname());
            pst.setString(4, apply.getFloorname());
            pst.setString(5, apply.getRoomname());
            pst.setString(6, apply.getShopname());
            pst.setString(7, apply.getSex());
            pst.setString(8, apply.getPhone());
            i = pst.executeUpdate();
            conn.commit();//提交以上操作
            pst.close();
        } catch (SQLException e){
            e.printStackTrace();
        }
        return i>0;
    }

    public boolean approval(Apply apply){
        OpenConnection db = new OpenConnection();
        Connection conn = db.getConnection();
        String sql="insert into apply(condition) values(?)";
        int i=0;
        try{
            conn.setAutoCommit(false);//设置为不自动提交
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setString(1,apply.getCondition());
            i = pst.executeUpdate();
            conn.commit();//提交以上操作
            pst.close();
        } catch (SQLException e){
            e.printStackTrace();
        }
        return i>0;
    }
}
